<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/16
 * Time: 22:21
 */

class Add_teacher_model extends MY_Model
{
    function add_teacher($data)
    {
//        var_dump($data);
//        var_dump(json_decode($data));
        $data = json_decode($data);
        if ($data === null) {
            $name = $data['name'];
            $sex = $data['sex'];
            $exec = $data['exec'];
            $school = $data['school'];
            $grade = $data['grade'];
            $class = $data['class'];
            $pos = $data['pos']; //文件列表
            $phone = $data['phone']; //家长电话
            $late_mark = $data['late_mark']; //文件列表
        } else {
            $name = $data->name;
            $sex = $data->sex;
            $exec = $data->exec;
            $school = $data->school;
            $grade = $data->grade;
            $class = $data->class;
            $pos = $data->pos;
            $phone = $data->phone;
            $late_mark = '';
        }

        $pass = substr($phone, -6);
        $last_date = date("Y.m.d");
        $sql = /** @lang text */
            "INSERT INTO ws_baseinfo(name,last_date,sex,exec,school,grade,class,pos,late_mark,phone,pass) VALUE('$name','$last_date',$sex,$exec,$school,$grade,$class,$pos,'$late_mark',$phone,$pass)";
//        $this->db->trans_start();
        $query = $this->db->query($sql);
//        $this->db->trans_complete();
        $error = $this->db->error();
        if ($query) {
            return json_encode(array('result' => SUCCESS, 'msg' => $this->config->item('mysql_msg')[$error['code']]));
        }
        return json_encode(array('result' => ERROR, 'msg' => $this->config->item('mysql_msg')[$error['code']], 'code' => $error['code']));
    }
}